package ie.nell;

import android.content.SharedPreferences;
import android.database.sqlite.SQLiteDatabase;
import android.os.Environment;
import android.preference.PreferenceManager;
import java.io.File;

/**
 *
 * @author sweibelzahl
 */
public class ApplicationSettings {

    public static SQLiteDatabase db;
    public static EventDBOpenHelper dbh;
    private static SharedPreferences preferences;
    private static SharedPreferences.Editor editor;
    private static String defaultScreenshotPath = "";
    
    public ApplicationSettings(UXBrowser uxb) {
        preferences = PreferenceManager.getDefaultSharedPreferences(uxb.getApplicationContext());

        File sdCard = Environment.getExternalStorageDirectory();
        defaultScreenshotPath = sdCard.getAbsolutePath() + "/Screenshots";
    }

    public static void setCurrentURL(String currentURL) {
        editor = preferences.edit();
        editor.putString("currentURL", currentURL);
        editor.commit();
    }

    public static void setDb(SQLiteDatabase db) {
        ApplicationSettings.db = db;
    }

    public static String getCurrentURL() {
        return preferences.getString("currentURL", "");
    }

    public static SQLiteDatabase getDb() {
        return db;
    }

    public static boolean isRecordClick() {
        return preferences.getBoolean("recordClick", true);
    }

    public static boolean isRecordPage() {
        return preferences.getBoolean("recordPage", true);
    }

    public static boolean isRecordScreen() {
        return preferences.getBoolean("recordScreen", false);
    }

    public static void setRecordClick(boolean recordClick) {
        editor = preferences.edit();
        editor.putBoolean("recordClick", recordClick);
        editor.commit();
    }

    public static void setRecordPage(boolean recordPage) {
        editor = preferences.edit();
        editor.putBoolean("recordPage", recordPage);
        editor.commit();
    }

    public static void setRecordScreen(boolean recordScreen) {
        editor = preferences.edit();
        editor.putBoolean("recordScreen", recordScreen);
        editor.commit();
    }

    public static String getScreenshotPath() {
        return preferences.getString("screenshotPath", defaultScreenshotPath);
    }

    public static void setScreenshotPath(String screenshotPath) {
        editor = preferences.edit();
        editor.putString("screenshotPath", screenshotPath);
        editor.commit();
    }    
}
